package com.cn.lp.ai.factory;

import cn.hutool.http.HttpRequest;
import org.springframework.ai.qianfan.api.QianFanApi;
import org.springframework.ai.qianfan.api.auth.AccessTokenResponse;
import org.springframework.ai.qianfan.api.auth.QianFanAccessToken;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Assert;
import org.springframework.web.client.RestClient;

public class TestService {

//    public ResponseEntity<QianFanApi.ChatCompletion> chatCompletionEntity(QianFanApi.ChatCompletionRequest chatRequest) {
//        Assert.notNull(chatRequest, "The request body can not be null.");
//        Assert.isTrue(!chatRequest.stream(), "Request must set the steam property to false.");
//        return ((RestClient.RequestBodySpec) HttpRequest.post(uri("/v1/wenxinworkshop/chat/{model}?access_token={token}",
//                new Object[]{chatRequest.model, this.getAccessToken()}))
//                .body(chatRequest).retrieve().toEntity(QianFanApi.ChatCompletion.class);
//    }
//
//    public QianFanAccessToken requestToken() {
//        ResponseEntity<AccessTokenResponse> tokenResponseEntity = this.restClient.get().uri("/oauth/2.0/token?client_id={clientId}&client_secret={clientSecret}&grant_type=client_credentials",
//                new Object[]{this.apiKey, this.secretKey}).retrieve().toEntity(AccessTokenResponse.class);
//        AccessTokenResponse tokenResponse = (AccessTokenResponse)tokenResponseEntity.getBody();
//        if (tokenResponse == null) {
//            throw new IllegalArgumentException("Failed to get access token, response is null");
//        } else if (tokenResponse.error() != null) {
//            String var10002 = tokenResponse.error();
//            throw new IllegalArgumentException("Failed to get access token, error: " + var10002 + ", error_description: " + tokenResponse.errorDescription());
//        } else {
//            return new QianFanAccessToken(tokenResponse);
//        }
//    }
}
